package com.hsh.gaoqianlianmeng.service.impl;

import com.hsh.gaoqianlianmeng.common.Result;
import com.hsh.gaoqianlianmeng.constants.filepath.GlobalPathConstants;
import com.hsh.gaoqianlianmeng.domain.Currency;
import com.hsh.gaoqianlianmeng.domain.ExchangeRate;
import com.hsh.gaoqianlianmeng.domain.Shop;
import com.hsh.gaoqianlianmeng.service.CurrencyService;
import com.hsh.gaoqianlianmeng.service.ShopService;
import com.hsh.gaoqianlianmeng.utils.POIExcelUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 店铺 Service
 */
@Service
public class CurrencyServiceImpl implements CurrencyService {


    /**
     * 获取币种列表
     *
     * @return
     */
    @Override
    public Result<List<Currency>> getCurrency() {
        List<Currency> currencies = POIExcelUtils.read(GlobalPathConstants.GLOBAL_FOLDER + GlobalPathConstants.CURRENCY_LIST
                , Currency.class);
        return Result.success(currencies);
    }

    /**
     * 获取汇率
     *
     * @param exchangeRate
     * @return
     */
    @Override
    public Result getExchangeRate(ExchangeRate exchangeRate) {
        List<ExchangeRate> exchangeRates = POIExcelUtils.read(GlobalPathConstants.GLOBAL_FOLDER + GlobalPathConstants.CURRENCY_LIST
                , ExchangeRate.class);
        exchangeRate.setExchangeRate("--");
        for (ExchangeRate er : exchangeRates) {
            if (exchangeRate.equals(er)){
                exchangeRate.setExchangeRate(er.getExchangeRate());
            }
        }
        return Result.success(exchangeRate);
    }
}
